Bug 1321509 - remove references to Array.slice in addon-sdk util/object;r=zer0
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 07 Dec 2016 18:03:32 +0100
changeset 325320 d72c318a4f42ab4d4e34d27be6a590fc5df619b9
parent 325319 61d6fe7c63903f8f3d5ba8e9af58f6893f763167
child 325321 b9b90a3362eaed6b77720905182ad4153d8b1dab
push id31051
push usercbook@mozilla.com
push dateThu, 08 Dec 2016 15:15:04 +0000
treeherdermozilla-central@64e024fe4471 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszer0
bugs1321509
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1321509 - remove references to Array.slice in addon-sdk util/object;r=zer0 MozReview-Commit-ID: 8HCwdqy4kwl
addon-sdk/source/lib/sdk/util/object.js
--- a/addon-sdk/source/lib/sdk/util/object.js
+++ b/addon-sdk/source/lib/sdk/util/object.js
@@ -4,16 +4,20 @@
 "use strict";
 
 module.metadata = {
   "stability": "unstable"
 };
 
 const { flatten } = require('./array');
 
+// Create a shortcut for Array.prototype.slice.call().
+const unbind = Function.call.bind(Function.bind, Function.call);
+const slice = unbind(Array.prototype.slice);
+
 /**
  * Merges all the properties of all arguments into first argument. If two or
  * more argument objects have own properties with the same name, the property
  * is overridden, with precedence from right to left, implying, that properties
  * of the object on the left are overridden by a same named property of the
  * object on the right.
  *
  * Any argument given with "falsy" value - commonly `null` and `undefined` in
@@ -29,33 +33,33 @@ const { flatten } = require('./array');
  *    b.name    // 'b'
  */
 function merge(source) {
   let descriptor = {};
 
   // `Boolean` converts the first parameter to a boolean value. Any object is
   // converted to `true` where `null` and `undefined` becames `false`. Therefore
   // the `filter` method will keep only objects that are defined and not null.
-  Array.slice(arguments, 1).filter(Boolean).forEach(function onEach(properties) {
+  slice(arguments, 1).filter(Boolean).forEach(function onEach(properties) {
     getOwnPropertyIdentifiers(properties).forEach(function(name) {
       descriptor[name] = Object.getOwnPropertyDescriptor(properties, name);
     });
   });
   return Object.defineProperties(source, descriptor);
 }
 exports.merge = merge;
 
 /**
  * Returns an object that inherits from the first argument and contains all the
  * properties from all following arguments.
  * `extend(source1, source2, source3)` is equivalent of
  * `merge(Object.create(source1), source2, source3)`.
  */
 function extend(source) {
-  let rest = Array.slice(arguments, 1);
+  let rest = slice(arguments, 1);
   rest.unshift(Object.create(source));
   return merge.apply(null, rest);
 }
 exports.extend = extend;
 
 function has(obj, key) {
   return obj.hasOwnProperty(key);
 }
@@ -67,17 +71,17 @@ function each(obj, fn) {
 exports.each = each;
 
 /**
  * Like `merge`, except no property descriptors are manipulated, for use
  * with platform objects. Identical to underscore's `extend`. Useful for
  * merging XPCOM objects
  */
 function safeMerge(source) {
-  Array.slice(arguments, 1).forEach(function onEach (obj) {
+  slice(arguments, 1).forEach(function onEach (obj) {
     for (let prop in obj) source[prop] = obj[prop];
   });
   return source;
 }
 exports.safeMerge = safeMerge;
 
 /*
  * Returns a copy of the object without omitted properties