Repository: rtfeldman/seamless-immutable
Pull request #195 (2017-01-13 13:05:09)

Changed ImmutableError to be an instance of Error
Changes ImmutableError to be a custom error type instead of a generator/factory function.

This should fix https://github.com/rtfeldman/seamless-immutable/issues/143

Based on suggestions here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types


Patch:
diff --git a/seamless-immutable.development.js b/seamless-immutable.development.js
index d17773e..84e6f50 100644
--- a/seamless-immutable.development.js
+++ b/seamless-immutable.development.js
@@ -99,13 +99,12 @@ function immutableInit(config) {
   ]);
 
   function ImmutableError(message) {
-    var err       = new Error(message);
-    // TODO: Consider `Object.setPrototypeOf(err, ImmutableError);`
-    err.__proto__ = ImmutableError;
-
-    return err;
+    this.name = 'MyError';
+    this.message = message;
+    this.stack = (new Error()).stack;
   }
-  ImmutableError.prototype = Error.prototype;
+  ImmutableError.prototype = new Error;
+  ImmutableError.prototype.constructor = Error;
 
   function makeImmutable(obj, bannedMethods) {
     // Tag it so we can quickly tell it's immutable later.
diff --git a/seamless-immutable.development.min.js b/seamless-immutable.development.min.js
index 627deb9..0d771f9 100644
--- a/seamless-immutable.development.min.js
+++ b/seamless-immutable.development.min.js
@@ -1,1 +1,1 @@
-/* (c) 2016, Richard Feldman, github.com/rtfeldman/seamless-immutable/blob/master/LICENSE */!function(){"use strict";function a(b){function c(a){return"object"==typeof a&&!Array.isArray(a)&&null!==a}function d(a){var b=Object.getPrototypeOf(a);return b?Object.create(b):{}}function e(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function f(a,b){e(a,b,function(){throw new k("The "+b+" method cannot be invoked on an Immutable data structure.")})}function g(a){e(a,R,!0)}function h(a){return"object"==typeof a?null===a||Boolean(Object.getOwnPropertyDescriptor(a,R)):!0}function i(a,b){return a===b||a!==a&&b!==b}function j(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function k(a){var b=new Error(a);return b.__proto__=k,b}function l(a,b){g(a);for(var c in b)b.hasOwnProperty(c)&&f(a,b[c]);return Object.freeze(a),a}function m(a,b){var c=a[b];e(a,b,function(){return K(c.apply(a,arguments))})}function n(a,b,c){var d=c&&c.deep;if(a in this&&(d&&this[a]!==b&&j(b)&&j(this[a])&&(b=K.merge(this[a],b,{deep:!0,mode:"replace"})),i(this[a],b)))return this;var e=u.call(this);return e[a]=K(b),p(e)}function o(a,b,c){var d=a[0];if(1===a.length)return n.call(this,d,b,c);var e,f=a.slice(1),g=this[d];if("object"==typeof g&&null!==g)e=K.setIn(g,f,b);else{var h=f[0];e=""!==h&&isFinite(h)?o.call(X,f,b):A.call(Y,f,b)}if(d in this&&g===e)return this;var i=u.call(this);return i[d]=e,p(i)}function p(a){for(var b in V)if(V.hasOwnProperty(b)){var c=V[b];m(a,c)}Q.use_static||(e(a,"flatMap",s),e(a,"asObject",v),e(a,"asMutable",u),e(a,"set",n),e(a,"setIn",o),e(a,"update",C),e(a,"updateIn",E));for(var d=0,f=a.length;f>d;d++)a[d]=K(a[d]);return l(a,U)}function q(a){return Q.use_static||e(a,"asMutable",r),l(a,W)}function r(){return new Date(this.getTime())}function s(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this);Array.isArray(e)?c.push.apply(c,e):c.push(e)}return p(c)}function t(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=Array.isArray(a)?a.slice():Array.prototype.slice.call(arguments);b.forEach(function(a,b,c){"number"==typeof a&&(c[b]=a.toString())}),a=function(a,c){return-1!==b.indexOf(c)}}var c=d(this);for(var e in this)this.hasOwnProperty(e)&&a(this[e],e)===!1&&(c[e]=this[e]);return H(c)}function u(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(w(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function v(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return H(c)}function w(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,R)||a instanceof Date?a:K.asMutable(a,{deep:!0})}function x(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function y(a,b){function c(a,c,e){var g=K(c[e]),h=m&&m(a[e],g,b),l=a[e];if(void 0!==f||void 0!==h||!a.hasOwnProperty(e)||!i(g,l)){var n;n=h?h:k&&j(l)&&j(g)?K.merge(l,g,b):g,i(l,n)&&a.hasOwnProperty(e)||(void 0===f&&(f=x(a,d(a))),f[e]=n)}}function e(a,b){for(var c in a)b.hasOwnProperty(c)||(void 0===f&&(f=x(a,d(a))),delete f[c])}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var f,g,h=Array.isArray(a),k=b&&b.deep,l=b&&b.mode||"merge",m=b&&b.merger;if(h)for(var n=0,o=a.length;o>n;n++){var p=a[n];for(g in p)p.hasOwnProperty(g)&&c(void 0!==f?f:this,p,g)}else{for(g in a)Object.getOwnPropertyDescriptor(a,g)&&c(this,a,g);"replace"===l&&e(this,a)}return void 0===f?this:H(f)}function z(a,b){var c=b&&b.deep;if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#replace can only be invoked with objects or arrays, not "+JSON.stringify(a));return K.merge(this,a,{deep:c,mode:"replace"})}function A(a,b,c){if(!(a instanceof Array)||0===a.length)throw new TypeError('The first argument to Immutable#setIn must be an array containing at least one "key" string.');var e=a[0];if(1===a.length)return B.call(this,e,b,c);var f,g=a.slice(1),h=this[e];if(f=this.hasOwnProperty(e)&&"object"==typeof h&&null!==h?K.setIn(h,g,b):A.call(Y,g,b),this.hasOwnProperty(e)&&h===f)return this;var i=x(this,d(this));return i[e]=f,H(i)}function B(a,b,c){var e=c&&c.deep;if(this.hasOwnProperty(a)&&(e&&this[a]!==b&&j(b)&&j(this[a])&&(b=K.merge(this[a],b,{deep:!0,mode:"replace"})),i(this[a],b)))return this;var f=x(this,d(this));return f[a]=K(b),H(f)}function C(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return K.set(this,a,b.apply(d,[d].concat(c)))}function D(a,b){for(var c=0,d=b.length;null!=a&&d>c;c++)a=a[b[c]];return c&&c==d?a:void 0}function E(a,b){var c=Array.prototype.slice.call(arguments,2),d=D(this,a);return K.setIn(this,a,b.apply(d,[d].concat(c)))}function F(a){var b,c=d(this);if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=w(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function G(){return{}}function H(a){return Q.use_static||(e(a,"merge",y),e(a,"replace",z),e(a,"without",t),e(a,"asMutable",F),e(a,"set",B),e(a,"setIn",A),e(a,"update",C),e(a,"updateIn",E)),l(a,S)}function I(a){return"object"==typeof a&&null!==a&&(a.$$typeof===P||a.$$typeof===O)}function J(a){return"undefined"!=typeof File&&a instanceof File}function K(a,b,c){if(h(a)||I(a)||J(a))return a;if(Array.isArray(a))return p(a.slice());if(a instanceof Date)return q(new Date(a.getTime()));var d=b&&b.prototype,e=d&&d!==Object.prototype?function(){return Object.create(d)}:G,f=e();if(null==c&&(c=64),0>=c)throw new k("Attempt to construct Immutable from a deeply nested object was detected. Have you tried to wrap an object with circular references (e.g. React element)? See https://github.com/rtfeldman/seamless-immutable/wiki/Deeply-nested-object-was-detected for details.");c-=1;for(var g in a)Object.getOwnPropertyDescriptor(a,g)&&(f[g]=K(a[g],void 0,c));return H(f)}function L(a){function b(){var b=[].slice.call(arguments),c=b.shift();return a.apply(c,b)}return b}function M(a,b){function c(){var c=[].slice.call(arguments),d=c.shift();return Array.isArray(d)?b.apply(d,c):a.apply(d,c)}return c}function N(a,b,c){function d(){var d=[].slice.call(arguments),e=d.shift();return Array.isArray(e)?b.apply(e,d):e instanceof Date?c.apply(e,d):a.apply(e,d)}return d}var O="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),P=60103,Q={use_static:!1};c(b)&&void 0!==b.use_static&&(Q.use_static=Boolean(b.use_static));var R="__immutable_invariants_hold",S=["setPrototypeOf"],T=["keys"],U=S.concat(["push","pop","sort","splice","shift","unshift","reverse"]),V=T.concat(["map","filter","slice","concat","reduce","reduceRight"]),W=S.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);k.prototype=Error.prototype;var X=K([]),Y=K({});return K.from=K,K.isImmutable=h,K.ImmutableError=k,K.merge=L(y),K.replace=L(z),K.without=L(t),K.asMutable=N(F,u,r),K.set=M(B,n),K.setIn=M(A,o),K.update=L(C),K.updateIn=L(E),K.flatMap=L(s),K.asObject=L(v),Q.use_static||(K["static"]=a({use_static:!0})),Object.freeze(K),K}var b=a();"function"==typeof define&&define.amd?define(function(){return b}):"object"==typeof module?module.exports=b:"object"==typeof exports?exports.Immutable=b:"object"==typeof window?window.Immutable=b:"object"==typeof global&&(global.Immutable=b)}();
\ No newline at end of file
+/* (c) 2016, Richard Feldman, github.com/rtfeldman/seamless-immutable/blob/master/LICENSE */!function(){"use strict";function a(b){function c(a){return"object"==typeof a&&!Array.isArray(a)&&null!==a}function d(a){var b=Object.getPrototypeOf(a);return b?Object.create(b):{}}function e(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function f(a,b){e(a,b,function(){throw new k("The "+b+" method cannot be invoked on an Immutable data structure.")})}function g(a){e(a,R,!0)}function h(a){return"object"!=typeof a||(null===a||Boolean(Object.getOwnPropertyDescriptor(a,R)))}function i(a,b){return a===b||a!==a&&b!==b}function j(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function k(a){this.name="MyError",this.message=a,this.stack=(new Error).stack}function l(a,b){g(a);for(var c in b)b.hasOwnProperty(c)&&f(a,b[c]);return Object.freeze(a),a}function m(a,b){var c=a[b];e(a,b,function(){return K(c.apply(a,arguments))})}function n(a,b,c){var d=c&&c.deep;if(a in this&&(d&&this[a]!==b&&j(b)&&j(this[a])&&(b=K.merge(this[a],b,{deep:!0,mode:"replace"})),i(this[a],b)))return this;var e=u.call(this);return e[a]=K(b),p(e)}function o(a,b,c){var d=a[0];if(1===a.length)return n.call(this,d,b,c);var e,f=a.slice(1),g=this[d];if("object"==typeof g&&null!==g)e=K.setIn(g,f,b);else{var h=f[0];e=""!==h&&isFinite(h)?o.call(X,f,b):A.call(Y,f,b)}if(d in this&&g===e)return this;var i=u.call(this);return i[d]=e,p(i)}function p(a){for(var b in V)if(V.hasOwnProperty(b)){var c=V[b];m(a,c)}Q.use_static||(e(a,"flatMap",s),e(a,"asObject",v),e(a,"asMutable",u),e(a,"set",n),e(a,"setIn",o),e(a,"update",C),e(a,"updateIn",E));for(var d=0,f=a.length;d<f;d++)a[d]=K(a[d]);return l(a,U)}function q(a){return Q.use_static||e(a,"asMutable",r),l(a,W)}function r(){return new Date(this.getTime())}function s(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;b<d;b++){var e=a(this[b],b,this);Array.isArray(e)?c.push.apply(c,e):c.push(e)}return p(c)}function t(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=Array.isArray(a)?a.slice():Array.prototype.slice.call(arguments);b.forEach(function(a,b,c){"number"==typeof a&&(c[b]=a.toString())}),a=function(a,c){return b.indexOf(c)!==-1}}var c=d(this);for(var e in this)this.hasOwnProperty(e)&&a(this[e],e)===!1&&(c[e]=this[e]);return H(c)}function u(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;b<c;b++)d.push(w(this[b]));else for(b=0,c=this.length;b<c;b++)d.push(this[b]);return d}function v(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;b<d;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return H(c)}function w(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,R)||a instanceof Date?a:K.asMutable(a,{deep:!0})}function x(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function y(a,b){function c(a,c,e){var g=K(c[e]),h=m&&m(a[e],g,b),l=a[e];if(void 0!==f||void 0!==h||!a.hasOwnProperty(e)||!i(g,l)){var n;n=h?h:k&&j(l)&&j(g)?K.merge(l,g,b):g,i(l,n)&&a.hasOwnProperty(e)||(void 0===f&&(f=x(a,d(a))),f[e]=n)}}function e(a,b){for(var c in a)b.hasOwnProperty(c)||(void 0===f&&(f=x(a,d(a))),delete f[c])}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var f,g,h=Array.isArray(a),k=b&&b.deep,l=b&&b.mode||"merge",m=b&&b.merger;if(h)for(var n=0,o=a.length;n<o;n++){var p=a[n];for(g in p)p.hasOwnProperty(g)&&c(void 0!==f?f:this,p,g)}else{for(g in a)Object.getOwnPropertyDescriptor(a,g)&&c(this,a,g);"replace"===l&&e(this,a)}return void 0===f?this:H(f)}function z(a,b){var c=b&&b.deep;if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#replace can only be invoked with objects or arrays, not "+JSON.stringify(a));return K.merge(this,a,{deep:c,mode:"replace"})}function A(a,b,c){if(!(a instanceof Array)||0===a.length)throw new TypeError('The first argument to Immutable#setIn must be an array containing at least one "key" string.');var e=a[0];if(1===a.length)return B.call(this,e,b,c);var f,g=a.slice(1),h=this[e];if(f=this.hasOwnProperty(e)&&"object"==typeof h&&null!==h?K.setIn(h,g,b):A.call(Y,g,b),this.hasOwnProperty(e)&&h===f)return this;var i=x(this,d(this));return i[e]=f,H(i)}function B(a,b,c){var e=c&&c.deep;if(this.hasOwnProperty(a)&&(e&&this[a]!==b&&j(b)&&j(this[a])&&(b=K.merge(this[a],b,{deep:!0,mode:"replace"})),i(this[a],b)))return this;var f=x(this,d(this));return f[a]=K(b),H(f)}function C(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return K.set(this,a,b.apply(d,[d].concat(c)))}function D(a,b){for(var c=0,d=b.length;null!=a&&c<d;c++)a=a[b[c]];return c&&c==d?a:void 0}function E(a,b){var c=Array.prototype.slice.call(arguments,2),d=D(this,a);return K.setIn(this,a,b.apply(d,[d].concat(c)))}function F(a){var b,c=d(this);if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=w(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function G(){return{}}function H(a){return Q.use_static||(e(a,"merge",y),e(a,"replace",z),e(a,"without",t),e(a,"asMutable",F),e(a,"set",B),e(a,"setIn",A),e(a,"update",C),e(a,"updateIn",E)),l(a,S)}function I(a){return"object"==typeof a&&null!==a&&(a.$$typeof===P||a.$$typeof===O)}function J(a){return"undefined"!=typeof File&&a instanceof File}function K(a,b,c){if(h(a)||I(a)||J(a))return a;if(Array.isArray(a))return p(a.slice());if(a instanceof Date)return q(new Date(a.getTime()));var d=b&&b.prototype,e=d&&d!==Object.prototype?function(){return Object.create(d)}:G,f=e();if(null==c&&(c=64),c<=0)throw new k("Attempt to construct Immutable from a deeply nested object was detected. Have you tried to wrap an object with circular references (e.g. React element)? See https://github.com/rtfeldman/seamless-immutable/wiki/Deeply-nested-object-was-detected for details.");c-=1;for(var g in a)Object.getOwnPropertyDescriptor(a,g)&&(f[g]=K(a[g],void 0,c));return H(f)}function L(a){function b(){var b=[].slice.call(arguments),c=b.shift();return a.apply(c,b)}return b}function M(a,b){function c(){var c=[].slice.call(arguments),d=c.shift();return Array.isArray(d)?b.apply(d,c):a.apply(d,c)}return c}function N(a,b,c){function d(){var d=[].slice.call(arguments),e=d.shift();return Array.isArray(e)?b.apply(e,d):e instanceof Date?c.apply(e,d):a.apply(e,d)}return d}var O="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),P=60103,Q={use_static:!1};c(b)&&void 0!==b.use_static&&(Q.use_static=Boolean(b.use_static));var R="__immutable_invariants_hold",S=["setPrototypeOf"],T=["keys"],U=S.concat(["push","pop","sort","splice","shift","unshift","reverse"]),V=T.concat(["map","filter","slice","concat","reduce","reduceRight"]),W=S.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);k.prototype=new Error,k.prototype.constructor=Error;var X=K([]),Y=K({});return K.from=K,K.isImmutable=h,K.ImmutableError=k,K.merge=L(y),K.replace=L(z),K.without=L(t),K.asMutable=N(F,u,r),K.set=M(B,n),K.setIn=M(A,o),K.update=L(C),K.updateIn=L(E),K.flatMap=L(s),K.asObject=L(v),Q.use_static||(K["static"]=a({use_static:!0})),Object.freeze(K),K}var b=a();"function"==typeof define&&define.amd?define(function(){return b}):"object"==typeof module?module.exports=b:"object"==typeof exports?exports.Immutable=b:"object"==typeof window?window.Immutable=b:"object"==typeof global&&(global.Immutable=b)}();
\ No newline at end of file
diff --git a/seamless-immutable.production.min.js b/seamless-immutable.production.min.js
index b53c09c..9f70195 100644
--- a/seamless-immutable.production.min.js
+++ b/seamless-immutable.production.min.js
@@ -1,1 +1,1 @@
-/* (c) 2016, Richard Feldman, github.com/rtfeldman/seamless-immutable/blob/master/LICENSE */!function(){"use strict";function a(b){function c(a){return"object"==typeof a&&!Array.isArray(a)&&null!==a}function d(a){var b=Object.getPrototypeOf(a);return b?Object.create(b):{}}function e(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function f(a){e(a,Q,!0)}function g(a){return"object"==typeof a?null===a||Boolean(Object.getOwnPropertyDescriptor(a,Q)):!0}function h(a,b){return a===b||a!==a&&b!==b}function i(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function j(a){var b=new Error(a);return b.__proto__=j,b}function k(a,b){f(a);return a}function l(a,b){var c=a[b];e(a,b,function(){return J(c.apply(a,arguments))})}function m(a,b,c){var d=c&&c.deep;if(a in this&&(d&&this[a]!==b&&i(b)&&i(this[a])&&(b=J.merge(this[a],b,{deep:!0,mode:"replace"})),h(this[a],b)))return this;var e=t.call(this);return e[a]=J(b),o(e)}function n(a,b,c){var d=a[0];if(1===a.length)return m.call(this,d,b,c);var e,f=a.slice(1),g=this[d];if("object"==typeof g&&null!==g)e=J.setIn(g,f,b);else{var h=f[0];e=""!==h&&isFinite(h)?n.call(W,f,b):z.call(X,f,b)}if(d in this&&g===e)return this;var i=t.call(this);return i[d]=e,o(i)}function o(a){for(var b in U)if(U.hasOwnProperty(b)){var c=U[b];l(a,c)}P.use_static||(e(a,"flatMap",r),e(a,"asObject",u),e(a,"asMutable",t),e(a,"set",m),e(a,"setIn",n),e(a,"update",B),e(a,"updateIn",D));for(var d=0,f=a.length;f>d;d++)a[d]=J(a[d]);return k(a,T)}function p(a){return P.use_static||e(a,"asMutable",q),k(a,V)}function q(){return new Date(this.getTime())}function r(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this);Array.isArray(e)?c.push.apply(c,e):c.push(e)}return o(c)}function s(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=Array.isArray(a)?a.slice():Array.prototype.slice.call(arguments);b.forEach(function(a,b,c){"number"==typeof a&&(c[b]=a.toString())}),a=function(a,c){return-1!==b.indexOf(c)}}var c=d(this);for(var e in this)this.hasOwnProperty(e)&&a(this[e],e)===!1&&(c[e]=this[e]);return G(c)}function t(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(v(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function u(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return G(c)}function v(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,Q)||a instanceof Date?a:J.asMutable(a,{deep:!0})}function w(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function x(a,b){function c(a,c,e){var g=J(c[e]),j=m&&m(a[e],g,b),l=a[e];if(void 0!==f||void 0!==j||!a.hasOwnProperty(e)||!h(g,l)){var n;n=j?j:k&&i(l)&&i(g)?J.merge(l,g,b):g,h(l,n)&&a.hasOwnProperty(e)||(void 0===f&&(f=w(a,d(a))),f[e]=n)}}function e(a,b){for(var c in a)b.hasOwnProperty(c)||(void 0===f&&(f=w(a,d(a))),delete f[c])}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var f,g,j=Array.isArray(a),k=b&&b.deep,l=b&&b.mode||"merge",m=b&&b.merger;if(j)for(var n=0,o=a.length;o>n;n++){var p=a[n];for(g in p)p.hasOwnProperty(g)&&c(void 0!==f?f:this,p,g)}else{for(g in a)Object.getOwnPropertyDescriptor(a,g)&&c(this,a,g);"replace"===l&&e(this,a)}return void 0===f?this:G(f)}function y(a,b){var c=b&&b.deep;if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#replace can only be invoked with objects or arrays, not "+JSON.stringify(a));return J.merge(this,a,{deep:c,mode:"replace"})}function z(a,b,c){if(!(a instanceof Array)||0===a.length)throw new TypeError('The first argument to Immutable#setIn must be an array containing at least one "key" string.');var e=a[0];if(1===a.length)return A.call(this,e,b,c);var f,g=a.slice(1),h=this[e];if(f=this.hasOwnProperty(e)&&"object"==typeof h&&null!==h?J.setIn(h,g,b):z.call(X,g,b),this.hasOwnProperty(e)&&h===f)return this;var i=w(this,d(this));return i[e]=f,G(i)}function A(a,b,c){var e=c&&c.deep;if(this.hasOwnProperty(a)&&(e&&this[a]!==b&&i(b)&&i(this[a])&&(b=J.merge(this[a],b,{deep:!0,mode:"replace"})),h(this[a],b)))return this;var f=w(this,d(this));return f[a]=J(b),G(f)}function B(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return J.set(this,a,b.apply(d,[d].concat(c)))}function C(a,b){for(var c=0,d=b.length;null!=a&&d>c;c++)a=a[b[c]];return c&&c==d?a:void 0}function D(a,b){var c=Array.prototype.slice.call(arguments,2),d=C(this,a);return J.setIn(this,a,b.apply(d,[d].concat(c)))}function E(a){var b,c=d(this);if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=v(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function F(){return{}}function G(a){return P.use_static||(e(a,"merge",x),e(a,"replace",y),e(a,"without",s),e(a,"asMutable",E),e(a,"set",A),e(a,"setIn",z),e(a,"update",B),e(a,"updateIn",D)),k(a,R)}function H(a){return"object"==typeof a&&null!==a&&(a.$$typeof===O||a.$$typeof===N)}function I(a){return"undefined"!=typeof File&&a instanceof File}function J(a,b,c){if(g(a)||H(a)||I(a))return a;if(Array.isArray(a))return o(a.slice());if(a instanceof Date)return p(new Date(a.getTime()));var d=b&&b.prototype,e=d&&d!==Object.prototype?function(){return Object.create(d)}:F,f=e();for(var h in a)Object.getOwnPropertyDescriptor(a,h)&&(f[h]=J(a[h],void 0,c));return G(f)}function K(a){function b(){var b=[].slice.call(arguments),c=b.shift();return a.apply(c,b)}return b}function L(a,b){function c(){var c=[].slice.call(arguments),d=c.shift();return Array.isArray(d)?b.apply(d,c):a.apply(d,c)}return c}function M(a,b,c){function d(){var d=[].slice.call(arguments),e=d.shift();return Array.isArray(e)?b.apply(e,d):e instanceof Date?c.apply(e,d):a.apply(e,d)}return d}var N="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),O=60103,P={use_static:!1};c(b)&&void 0!==b.use_static&&(P.use_static=Boolean(b.use_static));var Q="__immutable_invariants_hold",R=["setPrototypeOf"],S=["keys"],T=R.concat(["push","pop","sort","splice","shift","unshift","reverse"]),U=S.concat(["map","filter","slice","concat","reduce","reduceRight"]),V=R.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);j.prototype=Error.prototype;var W=J([]),X=J({});return J.from=J,J.isImmutable=g,J.ImmutableError=j,J.merge=K(x),J.replace=K(y),J.without=K(s),J.asMutable=M(E,t,q),J.set=L(A,m),J.setIn=L(z,n),J.update=K(B),J.updateIn=K(D),J.flatMap=K(r),J.asObject=K(u),P.use_static||(J["static"]=a({use_static:!0})),Object.freeze(J),J}var b=a();"function"==typeof define&&define.amd?define(function(){return b}):"object"==typeof module?module.exports=b:"object"==typeof exports?exports.Immutable=b:"object"==typeof window?window.Immutable=b:"object"==typeof global&&(global.Immutable=b)}();
\ No newline at end of file
+/* (c) 2016, Richard Feldman, github.com/rtfeldman/seamless-immutable/blob/master/LICENSE */!function(){"use strict";function a(b){function c(a){return"object"==typeof a&&!Array.isArray(a)&&null!==a}function d(a){var b=Object.getPrototypeOf(a);return b?Object.create(b):{}}function e(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function f(a){e(a,Q,!0)}function g(a){return"object"!=typeof a||(null===a||Boolean(Object.getOwnPropertyDescriptor(a,Q)))}function h(a,b){return a===b||a!==a&&b!==b}function i(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function j(a){this.name="MyError",this.message=a,this.stack=(new Error).stack}function k(a,b){f(a);return a}function l(a,b){var c=a[b];e(a,b,function(){return J(c.apply(a,arguments))})}function m(a,b,c){var d=c&&c.deep;if(a in this&&(d&&this[a]!==b&&i(b)&&i(this[a])&&(b=J.merge(this[a],b,{deep:!0,mode:"replace"})),h(this[a],b)))return this;var e=t.call(this);return e[a]=J(b),o(e)}function n(a,b,c){var d=a[0];if(1===a.length)return m.call(this,d,b,c);var e,f=a.slice(1),g=this[d];if("object"==typeof g&&null!==g)e=J.setIn(g,f,b);else{var h=f[0];e=""!==h&&isFinite(h)?n.call(W,f,b):z.call(X,f,b)}if(d in this&&g===e)return this;var i=t.call(this);return i[d]=e,o(i)}function o(a){for(var b in U)if(U.hasOwnProperty(b)){var c=U[b];l(a,c)}P.use_static||(e(a,"flatMap",r),e(a,"asObject",u),e(a,"asMutable",t),e(a,"set",m),e(a,"setIn",n),e(a,"update",B),e(a,"updateIn",D));for(var d=0,f=a.length;d<f;d++)a[d]=J(a[d]);return k(a,T)}function p(a){return P.use_static||e(a,"asMutable",q),k(a,V)}function q(){return new Date(this.getTime())}function r(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;b<d;b++){var e=a(this[b],b,this);Array.isArray(e)?c.push.apply(c,e):c.push(e)}return o(c)}function s(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=Array.isArray(a)?a.slice():Array.prototype.slice.call(arguments);b.forEach(function(a,b,c){"number"==typeof a&&(c[b]=a.toString())}),a=function(a,c){return b.indexOf(c)!==-1}}var c=d(this);for(var e in this)this.hasOwnProperty(e)&&a(this[e],e)===!1&&(c[e]=this[e]);return G(c)}function t(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;b<c;b++)d.push(v(this[b]));else for(b=0,c=this.length;b<c;b++)d.push(this[b]);return d}function u(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;b<d;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return G(c)}function v(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,Q)||a instanceof Date?a:J.asMutable(a,{deep:!0})}function w(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function x(a,b){function c(a,c,e){var g=J(c[e]),j=m&&m(a[e],g,b),l=a[e];if(void 0!==f||void 0!==j||!a.hasOwnProperty(e)||!h(g,l)){var n;n=j?j:k&&i(l)&&i(g)?J.merge(l,g,b):g,h(l,n)&&a.hasOwnProperty(e)||(void 0===f&&(f=w(a,d(a))),f[e]=n)}}function e(a,b){for(var c in a)b.hasOwnProperty(c)||(void 0===f&&(f=w(a,d(a))),delete f[c])}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var f,g,j=Array.isArray(a),k=b&&b.deep,l=b&&b.mode||"merge",m=b&&b.merger;if(j)for(var n=0,o=a.length;n<o;n++){var p=a[n];for(g in p)p.hasOwnProperty(g)&&c(void 0!==f?f:this,p,g)}else{for(g in a)Object.getOwnPropertyDescriptor(a,g)&&c(this,a,g);"replace"===l&&e(this,a)}return void 0===f?this:G(f)}function y(a,b){var c=b&&b.deep;if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#replace can only be invoked with objects or arrays, not "+JSON.stringify(a));return J.merge(this,a,{deep:c,mode:"replace"})}function z(a,b,c){if(!(a instanceof Array)||0===a.length)throw new TypeError('The first argument to Immutable#setIn must be an array containing at least one "key" string.');var e=a[0];if(1===a.length)return A.call(this,e,b,c);var f,g=a.slice(1),h=this[e];if(f=this.hasOwnProperty(e)&&"object"==typeof h&&null!==h?J.setIn(h,g,b):z.call(X,g,b),this.hasOwnProperty(e)&&h===f)return this;var i=w(this,d(this));return i[e]=f,G(i)}function A(a,b,c){var e=c&&c.deep;if(this.hasOwnProperty(a)&&(e&&this[a]!==b&&i(b)&&i(this[a])&&(b=J.merge(this[a],b,{deep:!0,mode:"replace"})),h(this[a],b)))return this;var f=w(this,d(this));return f[a]=J(b),G(f)}function B(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return J.set(this,a,b.apply(d,[d].concat(c)))}function C(a,b){for(var c=0,d=b.length;null!=a&&c<d;c++)a=a[b[c]];return c&&c==d?a:void 0}function D(a,b){var c=Array.prototype.slice.call(arguments,2),d=C(this,a);return J.setIn(this,a,b.apply(d,[d].concat(c)))}function E(a){var b,c=d(this);if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=v(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function F(){return{}}function G(a){return P.use_static||(e(a,"merge",x),e(a,"replace",y),e(a,"without",s),e(a,"asMutable",E),e(a,"set",A),e(a,"setIn",z),e(a,"update",B),e(a,"updateIn",D)),k(a,R)}function H(a){return"object"==typeof a&&null!==a&&(a.$$typeof===O||a.$$typeof===N)}function I(a){return"undefined"!=typeof File&&a instanceof File}function J(a,b,c){if(g(a)||H(a)||I(a))return a;if(Array.isArray(a))return o(a.slice());if(a instanceof Date)return p(new Date(a.getTime()));var d=b&&b.prototype,e=d&&d!==Object.prototype?function(){return Object.create(d)}:F,f=e();for(var h in a)Object.getOwnPropertyDescriptor(a,h)&&(f[h]=J(a[h],void 0,c));return G(f)}function K(a){function b(){var b=[].slice.call(arguments),c=b.shift();return a.apply(c,b)}return b}function L(a,b){function c(){var c=[].slice.call(arguments),d=c.shift();return Array.isArray(d)?b.apply(d,c):a.apply(d,c)}return c}function M(a,b,c){function d(){var d=[].slice.call(arguments),e=d.shift();return Array.isArray(e)?b.apply(e,d):e instanceof Date?c.apply(e,d):a.apply(e,d)}return d}var N="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),O=60103,P={use_static:!1};c(b)&&void 0!==b.use_static&&(P.use_static=Boolean(b.use_static));var Q="__immutable_invariants_hold",R=["setPrototypeOf"],S=["keys"],T=R.concat(["push","pop","sort","splice","shift","unshift","reverse"]),U=S.concat(["map","filter","slice","concat","reduce","reduceRight"]),V=R.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);j.prototype=new Error,j.prototype.constructor=Error;var W=J([]),X=J({});return J.from=J,J.isImmutable=g,J.ImmutableError=j,J.merge=K(x),J.replace=K(y),J.without=K(s),J.asMutable=M(E,t,q),J.set=L(A,m),J.setIn=L(z,n),J.update=K(B),J.updateIn=K(D),J.flatMap=K(r),J.asObject=K(u),P.use_static||(J["static"]=a({use_static:!0})),Object.freeze(J),J}var b=a();"function"==typeof define&&define.amd?define(function(){return b}):"object"==typeof module?module.exports=b:"object"==typeof exports?exports.Immutable=b:"object"==typeof window?window.Immutable=b:"object"==typeof global&&(global.Immutable=b)}();
\ No newline at end of file
diff --git a/src/seamless-immutable.js b/src/seamless-immutable.js
index 67814dc..ad17933 100644
--- a/src/seamless-immutable.js
+++ b/src/seamless-immutable.js
@@ -99,13 +99,12 @@ function immutableInit(config) {
   ]);
 
   function ImmutableError(message) {
-    var err       = new Error(message);
-    // TODO: Consider `Object.setPrototypeOf(err, ImmutableError);`
-    err.__proto__ = ImmutableError;
-
-    return err;
+    this.name = 'MyError';
+    this.message = message;
+    this.stack = (new Error()).stack;
   }
-  ImmutableError.prototype = Error.prototype;
+  ImmutableError.prototype = new Error;
+  ImmutableError.prototype.constructor = Error;
 
   function makeImmutable(obj, bannedMethods) {
     // Tag it so we can quickly tell it's immutable later.


Test patch:
diff --git a/test/ImmutableArray/test-compat.js b/test/ImmutableArray/test-compat.js
index 4e80fd3..7d13afa 100644
--- a/test/ImmutableArray/test-compat.js
+++ b/test/ImmutableArray/test-compat.js
@@ -213,6 +213,8 @@ module.exports = function(config) {
       assert.throw(function() {
         array[methodName].apply(array, methodArgs);
       });
-    }, Immutable.ImmutableError);
+    }, function() { 
+      return new Immutable.ImmutableError(); 
+    });
   });
 };
diff --git a/test/ImmutableDate/test-compat.js b/test/ImmutableDate/test-compat.js
index ca260f0..5cf1707 100644
--- a/test/ImmutableDate/test-compat.js
+++ b/test/ImmutableDate/test-compat.js
@@ -86,7 +86,9 @@ module.exports = function(config) {
         assert.throw(function() {
           date[methodName].apply(date, methodArgs);
         });
-      }, Immutable.ImmutableError);
+      }, function() {
+        return new Immutable.ImmutableError();
+      });
     });
   });
 };
diff --git a/test/ImmutableError.spec.js b/test/ImmutableError.spec.js
new file mode 100644
index 0000000..5c7e2a1
--- /dev/null
+++ b/test/ImmutableError.spec.js
@@ -0,0 +1,18 @@
+var testCompat    = require("./ImmutableError/test-compat.js");
+var devBuild      = require("../seamless-immutable.development.js");
+var prodBuild     = require("../seamless-immutable.production.min.js");
+var getTestUtils  = require("./TestUtils.js");
+
+[
+  {id: "dev",  name: "Development build", implementation: devBuild},
+  {id: "prod", name: "Production build",  implementation: prodBuild}
+].forEach(function(config) {
+  var Immutable = config.implementation;
+  var TestUtils = getTestUtils(Immutable);
+
+  describe(config.name, function () {
+    describe("ImmutableError", function () {
+      testCompat(config);
+    });
+  });
+});
diff --git a/test/ImmutableError/test-compat.js b/test/ImmutableError/test-compat.js
new file mode 100644
index 0000000..65fe59a
--- /dev/null
+++ b/test/ImmutableError/test-compat.js
@@ -0,0 +1,23 @@
+var JSC          = require("jscheck");
+var assert       = require("chai").assert;
+var _            = require("lodash");
+var getTestUtils = require("../TestUtils.js");
+
+function notParseableAsInt(str) {
+  return parseInt(str).toString() !== str;
+}
+
+module.exports = function(config) {
+  var Immutable = config.implementation;
+  var TestUtils = getTestUtils(Immutable);
+
+  it("is an instance of ImmutableError", function () {
+    var e = new Immutable.ImmutableError();
+    assert.instanceOf(e, Immutable.ImmutableError);
+  });
+
+  it("is an instance of Error", function () {
+    var e = new Immutable.ImmutableError();
+    assert.instanceOf(e, Error);
+  });
+};