diff options
| author | Adam Kocoloski <adam.kocoloski@gmail.com> | 2011-01-20 12:43:37 -0500 | 
|---|---|---|
| committer | Adam Kocoloski <adam.kocoloski@gmail.com> | 2011-01-20 13:05:41 -0500 | 
| commit | f79d0a666a5fb9541a0925db5111208a94631065 (patch) | |
| tree | 392d85a8a9887ddc8f6268a48a65537b21734a7d /couchjs | |
| parent | 2ea18bdaa19ea7f2da1a5dccce65d50cf0efc64d (diff) | |
| parent | 94286611038e661487382ed834103853e88fdf69 (diff) | |
Merge CouchDB 1.0.2 release candidate
Conflicts:
	Makefile.am
	acinclude.m4.in
	apps/couch/src/couch_db.erl
	apps/couch/src/couch_db_updater.erl
	apps/couch/src/couch_rep.erl
	apps/couch/src/couch_rep_reader.erl
	apps/couch/src/couch_view.erl
	apps/couch/src/couch_view_group.erl
	rel/overlay/etc/default.ini
	share/Makefile.am
	src/couchdb/couch_query_servers.erl
	src/ibrowse/Makefile.am
	src/ibrowse/ibrowse.app.in
	src/ibrowse/ibrowse.erl
	src/ibrowse/ibrowse_app.erl
	src/ibrowse/ibrowse_http_client.erl
	src/ibrowse/ibrowse_lb.erl
	src/ibrowse/ibrowse_lib.erl
	src/ibrowse/ibrowse_sup.erl
	src/ibrowse/ibrowse_test.erl
	src/mochiweb/mochijson2.erl
	test/etap/112-replication-missing-revs.t
	test/etap/113-replication-attachment-comp.t
	test/etap/140-attachment-comp.t
Diffstat (limited to 'couchjs')
| -rw-r--r-- | couchjs/js/loop.js | 1 | ||||
| -rw-r--r-- | couchjs/js/util.js | 85 | ||||
| -rw-r--r-- | couchjs/js/views.js | 13 | 
3 files changed, 56 insertions, 43 deletions
| diff --git a/couchjs/js/loop.js b/couchjs/js/loop.js index 300151e9..a988684f 100644 --- a/couchjs/js/loop.js +++ b/couchjs/js/loop.js @@ -26,6 +26,7 @@ function init_sandbox() {      sandbox.start = Render.start;      sandbox.send = Render.send;      sandbox.getRow = Render.getRow; +    sandbox.isArray = isArray;    } catch (e) {      log(e.toSource());    } diff --git a/couchjs/js/util.js b/couchjs/js/util.js index 9cc464c3..b55480b9 100644 --- a/couchjs/js/util.js +++ b/couchjs/js/util.js @@ -10,36 +10,50 @@  // License for the specific language governing permissions and limitations under  // the License. -var resolveModule = function(names, parent, current, path) { +var resolveModule = function(names, mod, root) {    if (names.length == 0) { -    if (typeof current != "string") { +    if (typeof mod.current != "string") {        throw ["error","invalid_require_path", -        'Must require a JavaScript string, not: '+(typeof current)]; +        'Must require a JavaScript string, not: '+(typeof mod.current)]; +    } +    return { +      current : mod.current, +      parent : mod.parent, +      id : mod.id, +      exports : {}      } -    return [current, parent, path];    }    // we need to traverse the path    var n = names.shift();    if (n == '..') { -    if (!(parent && parent.parent)) { -      throw ["error", "invalid_require_path", 'Object has no parent '+JSON.stringify(current)]; +    if (!(mod.parent && mod.parent.parent)) { +      throw ["error", "invalid_require_path", 'Object has no parent '+JSON.stringify(mod.current)];      } -    path = path.slice(0, path.lastIndexOf('/')); -    return resolveModule(names, parent.parent.parent, parent.parent, path); +    return resolveModule(names, { +      id : mod.id.slice(0, mod.id.lastIndexOf('/')), +      parent : mod.parent.parent.parent, +      current : mod.parent.parent.current +    });    } else if (n == '.') { -    if (!parent) { -      throw ["error", "invalid_require_path", 'Object has no parent '+JSON.stringify(current)]; +    if (!mod.parent) { +      throw ["error", "invalid_require_path", 'Object has no parent '+JSON.stringify(mod.current)];      } -    return resolveModule(names, parent.parent, parent, path); +    return resolveModule(names, { +      parent : mod.parent.parent, +      current : mod.parent.current, +      id : mod.id +    }); +  } else if (root) { +    mod = {current : root};    } -  if (!current[n]) { -    throw ["error", "invalid_require_path", 'Object has no property "'+n+'". '+JSON.stringify(current)]; +  if (!mod.current[n]) { +    throw ["error", "invalid_require_path", 'Object has no property "'+n+'". '+JSON.stringify(mod.current)];    } -  var p = current; -  current = current[n]; -  current.parent = p; -  path = path ? path + '/' + n : n; -  return resolveModule(names, p, current, path); +  return resolveModule(names, { +    current : mod.current[n], +    parent : mod, +    id : mod.id ? mod.id + '/' + n : n +  });  };  var Couch = { @@ -52,19 +66,17 @@ var Couch = {      try {        if (sandbox) {          if (ddoc) { -          var require = function(name, parent) { -            if (!parent) {parent = {}}; -            var resolved = resolveModule(name.split('/'), parent.actual, ddoc, parent.id); -            var s = "function (module, exports, require) { " + resolved[0] + " }"; -            var module = {id:resolved[2], actual:resolved[1]}; -            module.exports = {}; +          var require = function(name, module) { +            module = module || {}; +            var newModule = resolveModule(name.split('/'), module, ddoc); +            var s = "function (module, exports, require) { " + newModule.current + " }";              try {                var func = sandbox ? evalcx(s, sandbox) : eval(s); -              func.apply(sandbox, [module, module.exports, function(name) {return require(name, module)}]); +              func.apply(sandbox, [newModule, newModule.exports, function(name) {return require(name, newModule)}]);              } catch(e) {                 throw ["error","compilation_error","Module require('"+name+"') raised error "+e.toSource()];               } -            return module.exports; +            return newModule.exports;            }            sandbox.require = require;          } @@ -84,10 +96,15 @@ var Couch = {    },    recursivelySeal : function(obj) {      // seal() is broken in current Spidermonkey -    seal(obj); +    try { +      seal(obj); +    } catch (x) { +      // Sealing of arrays broken in some SpiderMonkey versions. +      // https://bugzilla.mozilla.org/show_bug.cgi?id=449657 +    }      for (var propname in obj) { -      if (typeof doc[propname] == "object") { -        recursivelySeal(doc[propname]); +      if (typeof obj[propname] == "object") { +        arguments.callee(obj[propname]);        }      }    } @@ -105,8 +122,14 @@ function respond(obj) {  function log(message) {    // idea: query_server_config option for log level -  if (typeof message != "string") { +  if (typeof message == "xml") { +    message = message.toXMLString(); +  } else if (typeof message != "string") {      message = Couch.toJSON(message);    } -  respond(["log", message]); +  respond(["log", String(message)]);  }; + +function isArray(obj) { +  return toString.call(obj) === "[object Array]"; +} diff --git a/couchjs/js/views.js b/couchjs/js/views.js index ffe63377..2a15ee56 100644 --- a/couchjs/js/views.js +++ b/couchjs/js/views.js @@ -105,19 +105,8 @@ var Views = (function() {        // ]        // -      /* -      Immutable document support temporarily removed. +      Couch.recursivelySeal(doc); -      Removed because the seal function no longer works on JS 1.8 arrays, -      instead returning an error. The sealing is meant to prevent map -      functions from modifying the same document that is passed to other map -      functions. However, only map functions in the same design document are -      run together, so we have a reasonable expectation they can trust each -      other. Any map fun that can't be trusted can be placed in its own -      design document, and it cannot affect other map functions. - -      recursivelySeal(doc); // seal to prevent map functions from changing doc -      */        var buf = [];        for (var i = 0; i < State.funs.length; i++) {          map_results = []; | 
