From 51cd4f585887b17e4fc819a5d8de2d2e2165147b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Fr=C3=BChwirth?= Date: Thu, 3 Oct 2013 23:19:31 +0200 Subject: [PATCH 1/4] ringojs/rhino compatibility fix for missing __proto__ feature --- facet.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/facet.js b/facet.js index 3e1495b..7a96b87 100644 --- a/facet.js +++ b/facet.js @@ -16,6 +16,7 @@ var DatabaseError = require("./errors").DatabaseError, substitute = require("json-schema/lib/validate").substitute, rpcInvoke = require("./json-rpc").invoke; require("./coerce");// patches json-schema +require("./util/ringojs-compat"); // compatibility package for ringojs exports.Facet = Facet; Facet.facetFor = function(store, resolver, mediaType){ @@ -287,7 +288,7 @@ function FacetedStore(store, facetSchema){ } }; - constructor.__proto__ = httpHandlerPrototype; + constructor = Object.setPrototypeOf ( constructor, httpHandlerPrototype ); // TODO: handle immutable proto return constructor; @@ -543,6 +544,7 @@ var SchemaControlled = function(facetSchema, sourceClass, permissive){ } } } + for(var i in needSourceParameter){ // splice in the source argument for each method that needs it (function(param, protoFunc, i){ @@ -553,12 +555,12 @@ var SchemaControlled = function(facetSchema, sourceClass, permissive){ })(needSourceParameter[i], facetPrototype[i], i); } if(writableProto && partial === true){ - source.__proto__ = instancePrototype; + source = Object.setPrototypeOf ( source, instancePrototype ); wrapped = source; } else{ if(wrapped){ - wrapped.__proto__ = instancePrototype; + wrapped = Object.setPrototypeOf ( wrapped, instancePrototype ); } else{ wrapped = Object.create(instancePrototype); @@ -627,7 +629,7 @@ function Facet(appliesTo, schema, permissive){ facetedStore = function(){ return facetedStore.construct.apply(facetedStore, arguments); }; - facetedStore.__proto__ = baseFacetedStore; + facetedStore = Object.setPrototypeOf ( facetedStore, baseFacetedStore ); facetedStore.wrap = createWrap(facetedStore); } else{ From dfcdb2ebe986089b54ea263972cfb426b0772a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Fr=C3=BChwirth?= Date: Thu, 3 Oct 2013 23:24:15 +0200 Subject: [PATCH 2/4] ringojs/rhino compatibility layer, completes 51cd4f5 --- util/ringojs-compat.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 util/ringojs-compat.js diff --git a/util/ringojs-compat.js b/util/ringojs-compat.js new file mode 100644 index 0000000..cdf2173 --- /dev/null +++ b/util/ringojs-compat.js @@ -0,0 +1,24 @@ +// Polyfill for __proto__ and Object.setPrototypeOf +// see http://stackoverflow.com/questions/10476560/proto-when-will-it-be-gone-alternatives +// and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf +// and https://github.com/ringo/ringojs/issues/181 +var testobj = {}; +Object.setPrototypeOf = Object.setPrototypeOf || function ( obj, proto ) { + if ( testobj.__proto__ ) { + obj.__proto__ = proto; + return obj; + } + var type = typeof proto; + if ( ( typeof obj == "object" || typeof obj == "function" ) && ( type == "object" || type == "function" ) ) { + var constructor = function ( obj ) { + var ownPropertyNames = Object.getOwnPropertyNames ( obj ); + var length = ownPropertyNames.length; + for ( var i = 0; i < length; i++ ) { + var ownPropertyName = ownPropertyNames[i]; + this[ownPropertyName] = obj[ownPropertyName]; + } + }; + constructor.prototype = proto; + return new constructor(obj); + } else throw new TypeError ( "Expected both the arguments to be objects." ); +} \ No newline at end of file From 7557ca27558c6b3276d575e968848b662d549db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Fr=C3=BChwirth?= Date: Sat, 26 Oct 2013 20:52:24 +0200 Subject: [PATCH 3/4] call to "some" on data source in createWrap() now passes on return value of callback like it should --- facet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/facet.js b/facet.js index 7a96b87..3d4963d 100644 --- a/facet.js +++ b/facet.js @@ -355,7 +355,7 @@ var SchemaControlled = function(facetSchema, sourceClass, permissive){ var results = LazyArray({ some: function(callback){ source.some(function(item){ - callback((item && typeof item == "object" && wrap(item, transaction, item, true)) || item); + return callback((item && typeof item == "object" && wrap(item, transaction, item, true)) || item); }); }, length: source.length From 3e01e6219c502bdf2b4677951e065a72b030493f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Fr=C3=BChwirth?= Date: Sun, 27 Oct 2013 00:31:03 +0200 Subject: [PATCH 4/4] facet query result can now be real array instead of LazyArray by setting "lazy" flag on source to false --- facet.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/facet.js b/facet.js index 3d4963d..8dd82bc 100644 --- a/facet.js +++ b/facet.js @@ -361,6 +361,8 @@ var SchemaControlled = function(facetSchema, sourceClass, permissive){ length: source.length }); results.totalCount = source.totalCount; + if ( source.lazy == false ) + results = results.toRealArray (); return results; } var instancePrototype = Object.create(facetPrototype);