Skip to content

Commit 354b7df

Browse files
committed
apply csp patch
1 parent d53c40a commit 354b7df

File tree

12 files changed

+4793
-121
lines changed

12 files changed

+4793
-121
lines changed

build/grunt-tasks/build.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@
33
*/
44

55
module.exports = function (grunt) {
6-
grunt.registerTask('build', function () {
6+
7+
grunt.registerTask('build-vendor', function () {
8+
var webpack = require('webpack')
9+
webpack({
10+
entry: './node_modules/notevil/index.js',
11+
output: {
12+
path: './vendor',
13+
filename: 'notevil.js',
14+
library: 'notevil',
15+
libraryTarget: 'commonjs2'
16+
}
17+
}, this.async())
18+
})
19+
20+
grunt.registerTask('build-self', function () {
721

822
var done = this.async()
923
var fs = require('fs')
@@ -47,4 +61,6 @@ module.exports = function (grunt) {
4761
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
4862
}
4963
})
64+
65+
grunt.registerTask('build', ['build-vendor', 'build-self'])
5066
}

gruntfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ module.exports = function (grunt) {
2424
files: [
2525
'test/unit/lib/util.js',
2626
'test/unit/lib/jquery.js',
27+
'vendor/*.js',
2728
'src/**/*.js',
2829
'test/unit/specs/**/*.js'
2930
],
3031
preprocessors: {
32+
'vendor/*.js': ['commonjs'],
3133
'src/**/*.js': ['commonjs'],
3234
'test/unit/specs/**/*.js': ['commonjs']
3335
},
@@ -44,6 +46,7 @@ module.exports = function (grunt) {
4446
browsers: ['PhantomJS'],
4547
reporters: ['progress', 'coverage'],
4648
preprocessors: {
49+
'vendor/*.js': ['commonjs'],
4750
'src/**/*.js': ['commonjs', 'coverage'],
4851
'test/unit/specs/**/*.js': ['commonjs']
4952
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"karma-phantomjs-launcher": "^0.2.1",
4646
"karma-safari-launcher": "^0.1.1",
4747
"karma-sauce-launcher": "^0.2.14",
48+
"notevil": "^1.0.0",
4849
"phantomjs": "^1.9.17",
4950
"semver": "^5.0.1",
5051
"shell-task": "^1.0.0",

src/api/child.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ exports.$addChild = function (opts, BaseCtor) {
2525
var ctors = context._childCtors
2626
ChildVue = ctors[BaseCtor.cid]
2727
if (!ChildVue) {
28-
var optionName = BaseCtor.options.name
29-
var className = optionName
30-
? _.classify(optionName)
31-
: 'VueComponent'
32-
ChildVue = new Function(
33-
'return function ' + className + ' (options) {' +
34-
'this.constructor = ' + className + ';' +
35-
'this._init(options) }'
36-
)()
28+
ChildVue = function VueComponent (options) {
29+
this.constructor = ChildVue
30+
this._init(options)
31+
}
3732
ChildVue.options = BaseCtor.options
3833
ChildVue.linker = BaseCtor.linker
3934
ChildVue.prototype = context

src/api/global.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ var cid = 1
3636
exports.extend = function (extendOptions) {
3737
extendOptions = extendOptions || {}
3838
var Super = this
39-
var Sub = createClass(
40-
extendOptions.name ||
41-
Super.options.name ||
42-
'VueComponent'
43-
)
39+
var Sub = function VueComponent (options) {
40+
_.Vue.call(this, options)
41+
}
4442
Sub.prototype = Object.create(Super.prototype)
4543
Sub.prototype.constructor = Sub
4644
Sub.cid = cid++
@@ -59,22 +57,6 @@ exports.extend = function (extendOptions) {
5957
return Sub
6058
}
6159

62-
/**
63-
* A function that returns a sub-class constructor with the
64-
* given name. This gives us much nicer output when
65-
* logging instances in the console.
66-
*
67-
* @param {String} name
68-
* @return {Function}
69-
*/
70-
71-
function createClass (name) {
72-
return new Function(
73-
'return function ' + _.classify(name) +
74-
' (options) { this._init(options) }'
75-
)()
76-
}
77-
7860
/**
7961
* Plugin system
8062
*

src/parsers/expression.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var _ = require('../util')
22
var Path = require('./path')
33
var Cache = require('../cache')
4+
var notevil = require('../../vendor/notevil')
45
var expressionCache = new Cache(1000)
56

67
var allowedKeywords =
@@ -173,7 +174,13 @@ function compilePathFns (exp) {
173174

174175
function makeGetter (body) {
175176
try {
176-
return new Function('scope', 'return ' + body + ';')
177+
var fn = notevil.Function(
178+
'scope', 'Math',
179+
'return ' + body + ';'
180+
)
181+
return function (scope) {
182+
return fn.call(this, scope, Math)
183+
}
177184
} catch (e) {
178185
process.env.NODE_ENV !== 'production' && _.warn(
179186
'Invalid expression. ' +
@@ -198,7 +205,15 @@ function makeGetter (body) {
198205

199206
function makeSetter (body) {
200207
try {
201-
return new Function('scope', 'value', body + '=value;')
208+
var fn = notevil.Function(
209+
'scope', 'value', 'Math',
210+
body + ' = value;'
211+
)
212+
return function (scope, value) {
213+
try {
214+
fn.call(this, scope, value, Math)
215+
} catch (e) {}
216+
}
202217
} catch (e) {
203218
process.env.NODE_ENV !== 'production' && _.warn(
204219
'Invalid setter function body: ' + body

src/parsers/path.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var _ = require('../util')
22
var Cache = require('../cache')
33
var pathCache = new Cache(1000)
4-
var identRE = exports.identRE = /^[$_a-zA-Z]+[\w$]*$/
4+
exports.identRE = /^[$_a-zA-Z]+[\w$]*$/
55

66
// actions
77
var APPEND = 0
@@ -229,25 +229,6 @@ function parsePath (path) {
229229
}
230230
}
231231

232-
/**
233-
* Format a accessor segment based on its type.
234-
*
235-
* @param {String} key
236-
* @return {Boolean}
237-
*/
238-
239-
function formatAccessor (key) {
240-
if (identRE.test(key)) { // identifier
241-
return '.' + key
242-
} else if (+key === key >>> 0) { // bracket index
243-
return '[' + key + ']'
244-
} else if (key.charAt(0) === '*') {
245-
return '[o' + formatAccessor(key.slice(1)) + ']'
246-
} else { // bracket string
247-
return '["' + key.replace(/"/g, '\\"') + '"]'
248-
}
249-
}
250-
251232
/**
252233
* Compiles a getter function with a fixed path.
253234
* The fixed path getter supresses errors.
@@ -257,8 +238,22 @@ function formatAccessor (key) {
257238
*/
258239

259240
exports.compileGetter = function (path) {
260-
var body = 'return o' + path.map(formatAccessor).join('')
261-
return new Function('o', body)
241+
return function get (obj) {
242+
var original = obj
243+
var segment
244+
for (var i = 0, l = path.length; i < l; i++) {
245+
segment = path[i]
246+
if (segment.charAt(0) === '*') {
247+
segment = original[segment.slice(1)]
248+
}
249+
obj = obj[segment]
250+
if (i === l - 1) {
251+
return obj
252+
} else if (!_.isObject(obj)) {
253+
return
254+
}
255+
}
256+
}
262257
}
263258

264259
/**

test/unit/specs/api/child_spec.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,4 @@ describe('Child API', function () {
6666
var child2 = vm.$addChild(null, Ctor)
6767
expect(child1.constructor).toBe(child2.constructor)
6868
})
69-
70-
it('Use proper constructor name with inherit', function () {
71-
var Ctor = Vue.extend({
72-
name: 'vue-test',
73-
inherit: true
74-
})
75-
var child = vm.$addChild(null, Ctor)
76-
expect(child.constructor.toString().match(/^function VueTest\s?\(/)).toBeTruthy()
77-
})
78-
7969
})

test/unit/specs/api/data_spec.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,6 @@ describe('Data API', function () {
4444
expect(hasWarned(_, 'Consider pre-initializing')).toBe(true)
4545
})
4646

47-
it('$set invalid', function () {
48-
// invalid, should throw
49-
if (leftHandThrows()) {
50-
// if creating a function with invalid left hand
51-
// expression throws, the exp parser will catch the
52-
// error and warn.
53-
vm.$set('c + d', 1)
54-
expect(hasWarned(_, 'Invalid setter function body')).toBe(true)
55-
} else {
56-
// otherwise it will throw when calling the setter.
57-
expect(function () {
58-
try {
59-
vm.$set('c + d', 1)
60-
} catch (e) {
61-
return true
62-
}
63-
}()).toBe(true)
64-
}
65-
})
66-
6747
it('$add', function () {
6848
vm._digest = jasmine.createSpy()
6949
vm.$add('c', 1)
@@ -187,16 +167,3 @@ describe('Data API', function () {
187167
}
188168

189169
})
190-
191-
/**
192-
* check if creating a new Function with invalid left-hand
193-
* assignment would throw
194-
*/
195-
196-
function leftHandThrows () {
197-
try {
198-
new Function('a + b = 1')
199-
} catch (e) {
200-
return true
201-
}
202-
}

test/unit/specs/api/global_spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ describe('Global API', function () {
1919
expect(Test.options.a).toBe(1)
2020
expect(Test.options.b).toBe(2)
2121
expect(Test.super).toBe(Vue)
22-
// function.name is not available in IE
23-
expect(Test.toString().match(/^function Test\s?\(/)).toBeTruthy()
2422
var t = new Test({
2523
a: 2
2624
})

test/unit/specs/parsers/expression_spec.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -198,33 +198,12 @@ var testCases = [
198198
expected: true,
199199
paths: []
200200
},
201-
{
202-
// Date global
203-
exp: 'Date.now() > new Date("2000-01-01")',
204-
scope: {},
205-
expected: true,
206-
paths: []
207-
},
208201
// typeof operator
209202
{
210203
exp: 'typeof test === "string"',
211204
scope: { test: '123' },
212205
expected: true,
213206
paths: ['test']
214-
},
215-
// isNaN
216-
{
217-
exp: 'isNaN(a)',
218-
scope: { a: 2 },
219-
expected: false,
220-
paths: ['a']
221-
},
222-
// parseFloat & parseInt
223-
{
224-
exp: 'parseInt(a, 10) + parseFloat(b)',
225-
scope: { a: 2.33, b: '3.45' },
226-
expected: 5.45,
227-
paths: ['a', 'b']
228207
}
229208
]
230209

0 commit comments

Comments
 (0)