]> git.parisson.com Git - pdf.js.git/commitdiff
We should use feature detection. Thanks @brendandahl
authorTim de Koning <github@kingsquare.nl>
Wed, 27 Jun 2012 16:30:43 +0000 (18:30 +0200)
committerTim de Koning <github@kingsquare.nl>
Thu, 28 Jun 2012 07:10:18 +0000 (09:10 +0200)
web/compatibility.js

index 540dff0b10f3c56de847c9dd110729f9b4c29fb6..825dce647a80ae795ee3c5f6c586e7a7812a5a4b 100644 (file)
     if (typeof Uint8Array.prototype.subarray === 'undefined') {
         Uint8Array.prototype.subarray = function subarray(start, end) {
           return new Uint8Array(this.slice(start, end));
-        }
+        };
         Float32Array.prototype.subarray = function subarray(start, end) {
             return new Float32Array(this.slice(start, end));
-        }
+        };
     }
 
     // some mobile version might not support Float64Array
 
 // Object.defineProperty() ?
 (function checkObjectDefinePropertyCompatibility() {
-  // safari 5 and 6 cannot use this on DOM objects and thus it's unusable,
-  if ((typeof Object.defineProperty !== 'undefined') &&
-    !/Safari/.test(navigator.userAgent)) return;
+  if (typeof Object.defineProperty !== 'undefined') {
+    // some browsers (e.g. safari) cannot use defineProperty() on DOM objects
+    // and thus the native version is not sufficient
+    var definePropertyPossible = true;
+    try {
+      Object.defineProperty(new Image(), 'id', { value: 'test' });
+    } catch (e) {
+      definePropertyPossible = false;
+    }
+    if (definePropertyPossible) return;
+  }
 
   Object.defineProperty = function objectDefineProperty(obj, name, def) {
     delete obj[name];