Skip to content

Commit d8a4f3a

Browse files
committed
1 parent 01ad85f commit d8a4f3a

File tree

408 files changed

+3790
-3687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

408 files changed

+3790
-3687
lines changed

bin/cli.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function completer (text) {
9696

9797
// scope variables
9898
for (const def in scope) {
99-
if (scope.hasOwnProperty(def)) {
99+
if (hasOwnProperty(scope, def)) {
100100
if (def.indexOf(keyword) === 0) {
101101
matches.push(def)
102102
}
@@ -113,7 +113,7 @@ function completer (text) {
113113
// math functions and constants
114114
const ignore = ['expr', 'type']
115115
for (const func in math.expression.mathWithTransform) {
116-
if (math.expression.mathWithTransform.hasOwnProperty(func)) {
116+
if (hasOwnProperty(math.expression.mathWithTransform, func)) {
117117
if (func.indexOf(keyword) === 0 && ignore.indexOf(func) === -1) {
118118
matches.push(func)
119119
}
@@ -122,24 +122,24 @@ function completer (text) {
122122

123123
// units
124124
const Unit = math.Unit
125-
for (let name in Unit.UNITS) {
126-
if (Unit.UNITS.hasOwnProperty(name)) {
125+
for (const name in Unit.UNITS) {
126+
if (hasOwnProperty(Unit.UNITS, name)) {
127127
if (name.indexOf(keyword) === 0) {
128128
matches.push(name)
129129
}
130130
}
131131
}
132-
for (let name in Unit.PREFIXES) {
133-
if (Unit.PREFIXES.hasOwnProperty(name)) {
132+
for (const name in Unit.PREFIXES) {
133+
if (hasOwnProperty(Unit.PREFIXES, name)) {
134134
const prefixes = Unit.PREFIXES[name]
135135
for (const prefix in prefixes) {
136-
if (prefixes.hasOwnProperty(prefix)) {
136+
if (hasOwnProperty(prefixes, prefix)) {
137137
if (prefix.indexOf(keyword) === 0) {
138138
matches.push(prefix)
139139
} else if (keyword.indexOf(prefix) === 0) {
140140
const unitKeyword = keyword.substring(prefix.length)
141141
for (const n in Unit.UNITS) {
142-
if (Unit.UNITS.hasOwnProperty(n)) {
142+
if (hasOwnProperty(Unit.UNITS, n)) {
143143
if (n.indexOf(unitKeyword) === 0 &&
144144
Unit.isValuelessUnit(prefix + n)) {
145145
matches.push(prefix + n)
@@ -424,3 +424,9 @@ if (version) {
424424
}
425425
})
426426
}
427+
428+
// helper function to safely check whether an object as a property
429+
// copy from the function in object.js which is ES6
430+
function hasOwnProperty (object, property) {
431+
return object && Object.hasOwnProperty.call(object, property)
432+
}

examples/advanced/custom_argument_parsing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ console.log(math.integrate(f, 0, 1)) // outputs 0.6667254718034714
9393
console.log(math.evaluate('integrate(x^0.5, x, 0, 1)')) // outputs 0.6667254718034714
9494

9595
// use the function via the expression parser (2)
96-
let scope = {}
96+
const scope = {}
9797
math.evaluate('f(x) = 2 * x', scope)
9898
console.log(math.evaluate('integrate(f(x), x, 0, 2)', scope)) // outputs 4.000000000000003

examples/advanced/more_secure_eval.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ const math = create(all)
2424
const limitedEvaluate = math.evaluate
2525

2626
math.import({
27-
'import': function () { throw new Error('Function import is disabled') },
28-
'createUnit': function () { throw new Error('Function createUnit is disabled') },
29-
'evaluate': function () { throw new Error('Function evaluate is disabled') },
30-
'parse': function () { throw new Error('Function parse is disabled') },
31-
'simplify': function () { throw new Error('Function simplify is disabled') },
32-
'derivative': function () { throw new Error('Function derivative is disabled') }
27+
import: function () { throw new Error('Function import is disabled') },
28+
createUnit: function () { throw new Error('Function createUnit is disabled') },
29+
evaluate: function () { throw new Error('Function evaluate is disabled') },
30+
parse: function () { throw new Error('Function parse is disabled') },
31+
simplify: function () { throw new Error('Function simplify is disabled') },
32+
derivative: function () { throw new Error('Function derivative is disabled') }
3333
}, { override: true })
3434

3535
console.log(limitedEvaluate('sqrt(16)')) // Ok, 4

examples/advanced/web_server/math_worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const math = create(all)
66
function noImport () {
77
throw new Error('function import is disabled.')
88
}
9-
math.import({ 'import': noImport }, { override: true })
9+
math.import({ import: noImport }, { override: true })
1010

1111
/**
1212
* Evaluate an expression

examples/expressions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ print(math.evaluate([
3636

3737
// provide a scope (just a regular JavaScript Object)
3838
console.log('\nevaluate expressions providing a scope with variables and functions')
39-
let scope = {
39+
const scope = {
4040
a: 3,
4141
b: 4
4242
}
@@ -84,7 +84,7 @@ console.log('\nprovide a scope')
8484
const node2 = math.parse('x^a')
8585
const code2 = node2.compile()
8686
print(node2.toString()) // "x ^ a"
87-
let scope2 = {
87+
const scope2 = {
8888
x: 3,
8989
a: 2
9090
}
@@ -115,7 +115,7 @@ print(code3.evaluate()) // 5
115115
// provide a scope for the variable assignment
116116
console.log('\nprovide a scope')
117117
const code4 = math.compile('a = a + 3')
118-
let scope3 = {
118+
const scope3 = {
119119
a: 7
120120
}
121121
code4.evaluate(scope3)

examples/objects.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ print(evaluate('{"name": "John"}')) // {"name": "John"}
1010
// create an object containing an object
1111
print(evaluate('{a: 2, b: {c: 3, d: 4}}')) // {"a": 2, "b": {"c": 3, "d": 4}}
1212

13-
let scope = {
13+
const scope = {
1414
obj: {
1515
prop: 42
1616
}

gulpfile.js

-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ function minify (done) {
169169

170170
log('Minified ' + FILE_MIN)
171171
log('Mapped ' + FILE_MAP)
172-
} catch (e) {
173-
throw e
174172
} finally {
175173
process.chdir(oldCwd)
176174
}

0 commit comments

Comments
 (0)