Browse Source

apply csp patch

Evan You 10 năm trước cách đây
mục cha
commit
94cf00d209

+ 6 - 3
build/build.js

@@ -26,7 +26,8 @@ rollup.rollup({
   entry: 'src/index.js',
   plugins: [
     babel({
-      loose: 'all'
+      loose: 'all',
+      exclude: 'lib/**'
     })
   ]
 })
@@ -45,7 +46,8 @@ rollup.rollup({
         'process.env.NODE_ENV': "'development'"
       }),
       babel({
-        loose: 'all'
+        loose: 'all',
+        exclude: 'lib/**'
       })
     ]
   })
@@ -66,7 +68,8 @@ rollup.rollup({
         'process.env.NODE_ENV': "'production'"
       }),
       babel({
-        loose: 'all'
+        loose: 'all',
+        exclude: 'lib/**'
       })
     ]
   })

+ 1 - 1
build/ci.sh

@@ -5,7 +5,7 @@ if [[ -z $CI_PULL_REQUEST ]] && [[ $CIRCLE_BRANCH = master ]]; then
   cat ./coverage/lcov.info | ./node_modules/.bin/codecov
   npm run build
   npm run e2e
-  npm run sauce-all
+  npm run sauce #csp only need Chrome/FF
 else
   npm test
 fi

+ 1 - 1
build/karma.cover.config.js

@@ -17,7 +17,7 @@ module.exports = function (config) {
   options.webpack.module.postLoaders = [
     {
       test: /\.js$/,
-      exclude: /test|node_modules/,
+      exclude: /test|node_modules|lib\//,
       loader: 'istanbul-instrumenter'
     }
   ]

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 433 - 0
lib/notevil.js


+ 2 - 1
package.json

@@ -35,7 +35,7 @@
     "unit": "karma start build/karma.unit.config.js",
     "cover": "karma start build/karma.cover.config.js",
     "sauce": "karma start build/karma.sauce.config.js",
-    "sauce-all": "npm run sauce && npm run sauce -- 1 && npm run sauce -- 2",
+    "sauce-all": "npm run sauce",
     "release": "bash build/release.sh",
     "release-csp": "bash build/release-csp.sh"
   },
@@ -69,6 +69,7 @@
     "karma-sauce-launcher": "^1.0.0",
     "karma-sourcemap-loader": "^0.3.7",
     "karma-webpack": "^1.7.0",
+    "notevil": "^1.0.0",
     "object-assign": "^4.0.1",
     "phantomjs": "^1.9.17",
     "rollup": "^0.34.13",

+ 3 - 20
src/global-api.js

@@ -18,7 +18,6 @@ import {
   del,
   nextTick,
   mergeOptions,
-  classify,
   toArray,
   commonTagRE,
   reservedTagRE,
@@ -104,7 +103,9 @@ export default function (Vue) {
         name = null
       }
     }
-    var Sub = createClass(name || 'VueComponent')
+    var Sub = function VueComponent (options) {
+      Vue.call(this, options)
+    }
     Sub.prototype = Object.create(Super.prototype)
     Sub.prototype.constructor = Sub
     Sub.cid = cid++
@@ -131,24 +132,6 @@ export default function (Vue) {
     return Sub
   }
 
-  /**
-   * A function that returns a sub-class constructor with the
-   * given name. This gives us much nicer output when
-   * logging instances in the console.
-   *
-   * @param {String} name
-   * @return {Function}
-   */
-
-  function createClass (name) {
-    /* eslint-disable no-new-func */
-    return new Function(
-      'return function ' + classify(name) +
-      ' (options) { this._init(options) }'
-    )()
-    /* eslint-enable no-new-func */
-  }
-
   /**
    * Plugin system
    *

+ 5 - 3
src/parsers/expression.js

@@ -1,3 +1,4 @@
+import notevil from '../../lib/notevil'
 import { warn } from '../util/index'
 import { parsePath, setPath } from './path'
 import Cache from '../cache'
@@ -138,9 +139,10 @@ function compileGetter (exp) {
 
 function makeGetterFn (body) {
   try {
-    /* eslint-disable no-new-func */
-    return new Function('scope', 'return ' + body + ';')
-    /* eslint-enable no-new-func */
+    var fn = notevil.Function('scope', 'Math', 'return ' + body)
+    return function (scope) {
+      return fn.call(this, scope, Math)
+    }
   } catch (e) {
     if (process.env.NODE_ENV !== 'production') {
       /* istanbul ignore if */

+ 0 - 2
test/unit/specs/global_api_spec.js

@@ -20,8 +20,6 @@ describe('Global API', function () {
     expect(Test.options.a).toBe(1)
     expect(Test.options.b).toBe(2)
     expect(Test.super).toBe(Vue)
-    // function.name is not available in IE
-    expect(Test.toString().match(/^function Test\s?\(/)).toBeTruthy()
     var t = new Test({
       a: 2
     })

+ 0 - 21
test/unit/specs/parsers/expression_spec.js

@@ -242,33 +242,12 @@ var testCases = [
     expected: undefined,
     paths: []
   },
-  {
-    // Date global
-    exp: 'Date.now() > new Date("2000-01-01")',
-    scope: {},
-    expected: true,
-    paths: []
-  },
   // typeof operator
   {
     exp: 'typeof test === "string"',
     scope: { test: '123' },
     expected: true,
     paths: ['test']
-  },
-  // isNaN
-  {
-    exp: 'isNaN(a)',
-    scope: { a: 2 },
-    expected: false,
-    paths: ['a']
-  },
-  // parseFloat & parseInt
-  {
-    exp: 'parseInt(a, 10) + parseFloat(b)',
-    scope: { a: 2.33, b: '3.45' },
-    expected: 5.45,
-    paths: ['a', 'b']
   }
 ]
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác