Use global namespace for overwriting String|Array prototypes
This commit is contained in:
parent
e8471d8edc
commit
94f85030e4
2 changed files with 16 additions and 15 deletions
20
lib/utils/prototypes.js
vendored
20
lib/utils/prototypes.js
vendored
|
@ -3,7 +3,7 @@
|
|||
* 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/. */
|
||||
|
||||
Object.defineProperty(String.prototype, 'fromCodePoint', function () {
|
||||
Object.defineProperty(global.String.prototype, 'fromCodePoint', function () {
|
||||
let chars = []
|
||||
let point, offset, units, i
|
||||
for (i = 0; i < arguments.length; ++i) {
|
||||
|
@ -19,33 +19,33 @@ Object.defineProperty(String.prototype, 'fromCodePoint', function () {
|
|||
return chars.join('')
|
||||
})
|
||||
|
||||
Object.defineProperty(String.prototype, 'endsWith', function (str) {
|
||||
Object.defineProperty(global.String.prototype, 'endsWith', function (str) {
|
||||
return this.match(str + '$') === str
|
||||
})
|
||||
|
||||
Object.defineProperty(String.prototype, 'startsWith', function (str) {
|
||||
Object.defineProperty(global.String.prototype, 'startsWith', function (str) {
|
||||
return this.match('^' + str) === str
|
||||
})
|
||||
|
||||
Object.defineProperty(String.prototype, 'trim', function () {
|
||||
Object.defineProperty(global.String.prototype, 'trim', function () {
|
||||
return this.replace(/^[\s\xA0]+/, '').replace(/[\s\xA0]+$/, '')
|
||||
})
|
||||
|
||||
Object.defineProperty(String.prototype, 'insert', function (data, idx) {
|
||||
Object.defineProperty(global.String.prototype, 'insert', function (data, idx) {
|
||||
return this.slice(0, idx) + data + this.slice(idx, this.length)
|
||||
})
|
||||
|
||||
Object.defineProperty(Array.prototype, 'has', function (v) {
|
||||
Object.defineProperty(global.Array.prototype, 'has', function (v) {
|
||||
return this.indexOf(v) !== -1
|
||||
})
|
||||
|
||||
Object.defineProperty(Array.prototype, 'forEach', function (array, fn) {
|
||||
Object.defineProperty(global.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) {
|
||||
Object.defineProperty(global.Array.prototype, 'map', function (fn, array) {
|
||||
let result = []
|
||||
Array.forEach(array, function (element) {
|
||||
result.push(fn(element))
|
||||
|
@ -53,7 +53,7 @@ Object.defineProperty(Array.prototype, 'map', function (fn, array) {
|
|||
return result
|
||||
})
|
||||
|
||||
Object.defineProperty(Array.prototype, 'extend', {
|
||||
Object.defineProperty(global.Array.prototype, 'extend', {
|
||||
value: function (obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
obj.forEach(function (v) {
|
||||
|
@ -67,7 +67,7 @@ Object.defineProperty(Array.prototype, 'extend', {
|
|||
}
|
||||
})
|
||||
|
||||
Object.defineProperty(Object, 'isObject', {
|
||||
Object.defineProperty(global.Object, 'isObject', {
|
||||
value: function (obj) {
|
||||
return (obj !== null && typeof obj === 'object' &&
|
||||
Object.prototype.toString.call(obj) === '[object Object]')
|
||||
|
|
11
package.json
11
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@mozillasecurity/octo",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"description": "",
|
||||
"keywords": [
|
||||
"fuzzing",
|
||||
|
@ -34,9 +34,11 @@
|
|||
"tests/**",
|
||||
"dist/"
|
||||
],
|
||||
"envs": [
|
||||
"browser"
|
||||
]
|
||||
"envs": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"cross-env": "^5.1.3",
|
||||
|
@ -46,7 +48,6 @@
|
|||
"grunt-standard": "*",
|
||||
"husky": "^0.14.3",
|
||||
"jshint": "^2.9.5",
|
||||
"jshint-loader": "^0.8.4",
|
||||
"karma": "*",
|
||||
"karma-chrome-launcher": "*",
|
||||
"karma-coverage": "*",
|
||||
|
|
Loading…
Reference in a new issue