From e6e5fcde1ef2e530952b91899c3fbf70a603eff6 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 6 Aug 2013 15:07:34 +0200 Subject: [PATCH] [IMP] Improved shim for function.bind bzr revid: nicolas.vanhoren@openerp.com-20130806130734-lov3aq0m4b1r4sto --- addons/web/__openerp__.py | 1 - addons/web/static/src/js/core.js | 25 ++++++++++++++++++++ addons/web/static/src/js/openerpframework.js | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index b2e589ed388..103e71c8290 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -13,7 +13,6 @@ This module provides the core of the OpenERP Web Client. 'auto_install': True, 'post_load': 'wsgi_postload', 'js' : [ - "static/src/fixbind.js", "static/lib/datejs/globalization/en-US.js", "static/lib/datejs/core.js", "static/lib/datejs/parser.js", diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 6a4d85f7204..6a30868e8ec 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -11,6 +11,31 @@ if (typeof(console) === "undefined") { }); } +// shim provided by mozilla for function.bind +if (!Function.prototype.bind) { + Function.prototype.bind = function (oThis) { + if (typeof this !== "function") { + // closest thing possible to the ECMAScript 5 internal IsCallable function + throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function () {}, + fBound = function () { + return fToBind.apply(this instanceof fNOP && oThis + ? this + : oThis, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + fNOP.prototype = this.prototype; + fBound.prototype = new fNOP(); + + return fBound; + }; +} + var instance = openerp; openerp.web.core = {}; diff --git a/addons/web/static/src/js/openerpframework.js b/addons/web/static/src/js/openerpframework.js index b5b245065f5..531893e1b1e 100644 --- a/addons/web/static/src/js/openerpframework.js +++ b/addons/web/static/src/js/openerpframework.js @@ -547,7 +547,7 @@ openerp.Widget = openerp.Class.extend(openerp.PropertiesMixin, { for (var name in this) { if(typeof(this[name]) == "function") { if((/^on_|^do_/).test(name)) { - this[name] = this[name].bind(this); + this[name] = _.bind(this[name], this); } } }