Henning Snater has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/57073


Change subject: (bug 44228) Checking if instanceof is supported correctly
......................................................................

(bug 44228) Checking if instanceof is supported correctly

Checking instanceof in IE8 will fail after having performed a deep extend on an 
object
containing a constructor with a custom prototype.

Change-Id: I0dfb0fb5b35ba8faf2b0ae1be2ba0dacc9946edc
---
M lib/resources/Resources.php
M lib/resources/jquery.wikibase/jquery.wikibase.listview.js
A lib/resources/wikibase.support.js
3 files changed, 39 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/73/57073/1

diff --git a/lib/resources/Resources.php b/lib/resources/Resources.php
index 49ed5f1..7ad25c8 100644
--- a/lib/resources/Resources.php
+++ b/lib/resources/Resources.php
@@ -41,6 +41,7 @@
                        'scripts' => array(
                                'wikibase.js',
                                'wikibase.Site.js',
+                               'wikibase.support.js',
                                'wikibase.RevisionStore.js'
                        ),
                        'dependencies' => array(
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.listview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
index 22c0305..c7dc5c2 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
@@ -80,7 +80,10 @@
                this._lia = this.options.listItemAdapter; // create short-cut 
for this
 
                if( typeof this._lia !== 'object'
-                       || !( this._lia instanceof 
$.wikibase.listview.ListItemAdapter )
+                       || wb.support.constructorDeepExtend
+                               && !( this._lia instanceof 
$.wikibase.listview.ListItemAdapter )
+                       // Just a simple check when the browser is not able to 
check for the instance:
+                       || !wb.support.constructorDeepExtend && 
!this._lia.liInstance
                ) {
                        throw new Error( "Option 'listItemAdapter' has to be an 
instance of $.wikibase." +
                                "listview.ListItemAdapter" );
diff --git a/lib/resources/wikibase.support.js 
b/lib/resources/wikibase.support.js
new file mode 100644
index 0000000..1bf14fd
--- /dev/null
+++ b/lib/resources/wikibase.support.js
@@ -0,0 +1,34 @@
+/**
+ * Browser feature detection routines.
+ *
+ * @file
+ * @ingroup WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author H. Snater < mediaw...@snater.com >
+ */
+( function( mw, wb, $ ) {
+       'use strict';
+
+       /**
+        * Returns an object holding information about whether certain features 
are supported in the
+        * user's browser.
+        */
+       wb.support = ( function() {
+               var support = {};
+
+               // Checking instanceof in IE8 will fail after having performed 
a deep extend on an object
+               // containing a constructor with a custom prototype.
+               support.constructorDeepExtend = true;
+               var test = function() { this.foo = ''; };
+               test.prototype = { bar: '' };
+
+               var derivate = new test(),
+                       extended = $.extend( true, {}, { member: derivate } );
+
+               support.constructorDeepExtend = ( extended.member instanceof 
test );
+
+               return support;
+       } )();
+
+} )( mediaWiki, wikibase, jQuery );

-- 
To view, visit https://gerrit.wikimedia.org/r/57073
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0dfb0fb5b35ba8faf2b0ae1be2ba0dacc9946edc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to