Fix prototypes and explicitly enable them

This commit is contained in:
Christoph Diehl 2018-03-22 00:08:55 +01:00
parent 9e97d0d59f
commit a869409853
No known key found for this signature in database
GPG key ID: 799CE5B68FEF404A
2 changed files with 44 additions and 66 deletions

View file

@ -3,57 +3,28 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Object.defineProperty(String.prototype, 'fromCodePoint', function () { const utils = require('../utils')
let chars = []
let point, offset, units, i class prototypes extends utils {
for (i = 0; i < arguments.length; ++i) { static enable () {
point = arguments[i] if (!String.prototype.hasOwnProperty('insert')) {
offset = point - 0x10000 Object.defineProperty(String.prototype, 'insert', {
units = point > 0xFFFF value: function (data, i) {
? [ return this.slice(0, i) + data + this.slice(i, this.length)
0xD800 + (offset >> 10),
0xDC00 + (offset & 0x3FF)]
: [point]
chars.push(String.fromCharCode.apply(null, units))
} }
return chars.join('')
})
Object.defineProperty(String.prototype, 'endsWith', function (str) {
return this.match(str + '$') === str
})
Object.defineProperty(String.prototype, 'startsWith', function (str) {
return this.match('^' + str) === str
})
Object.defineProperty(String.prototype, 'trim', function () {
return this.replace(/^[\s\xA0]+/, '').replace(/[\s\xA0]+$/, '')
})
Object.defineProperty(String.prototype, 'insert', function (data, idx) {
return this.slice(0, idx) + data + this.slice(idx, this.length)
})
Object.defineProperty(Array.prototype, 'has', function (v) {
return this.indexOf(v) !== -1
})
Object.defineProperty(Array.prototype, 'forEach', function (array, fn) {
for (let i = 0; i < array.length; i++) {
fn(array[i])
}
})
Object.defineProperty(Array.prototype, 'map', function (fn, array) {
let result = []
Array.forEach(array, function (element) {
result.push(fn(element))
}) })
return result }
})
Object.defineProperty(Array.prototype, 'extend', { if (!Array.prototype.hasOwnProperty('has')) {
Object.defineProperty(Array.prototype, 'has', {
value: function (v) {
return this.indexOf(v) !== -1
}
})
}
if (!Array.prototype.hasOwnProperty('extend')) {
Object.defineProperty(Array.prototype, 'extend', {
value: function (obj) { value: function (obj) {
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
obj.forEach(function (v) { obj.forEach(function (v) {
@ -65,11 +36,18 @@ Object.defineProperty(Array.prototype, 'extend', {
this.push(obj) this.push(obj)
} }
} }
}) })
}
Object.defineProperty(Object, 'isObject', { if (!Object.hasOwnProperty('isObject')) {
Object.defineProperty(Object, 'isObject', {
value: function (obj) { value: function (obj) {
return (obj !== null && typeof obj === 'object' && return (obj !== null && typeof obj === 'object' &&
Object.prototype.toString.call(obj) === '[object Object]') Object.prototype.toString.call(obj) === '[object Object]')
} }
}) })
}
}
}
module.exports = prototypes

View file

@ -1,6 +1,6 @@
{ {
"name": "@mozillasecurity/octo", "name": "@mozillasecurity/octo",
"version": "1.0.8", "version": "1.0.9",
"description": "", "description": "",
"keywords": [ "keywords": [
"fuzzing", "fuzzing",