From 94f85030e4b36e404ed9ebef08199f0aec96df25 Mon Sep 17 00:00:00 2001 From: Christoph Diehl <1614333+posidron@users.noreply.github.com> Date: Tue, 20 Mar 2018 00:03:55 +0100 Subject: [PATCH] Use global namespace for overwriting String|Array prototypes --- lib/utils/prototypes.js | 20 ++++++++++---------- package.json | 11 ++++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/utils/prototypes.js b/lib/utils/prototypes.js index e50d95c..62e6aec 100644 --- a/lib/utils/prototypes.js +++ b/lib/utils/prototypes.js @@ -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]') diff --git a/package.json b/package.json index c6d5a04..eeca90f 100644 --- a/package.json +++ b/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": "*",